﻿var oClose = document.getElementById('closeBox'), oLoginBox = document.getElementById('loginBox'), oShade = document.getElementById('shade'), iSpeed = scrollTop = 0, timer = null, oLoginBoxHeight = 308//弹出框的高度;

function moveTop(obj, iTarget) {
    clearInterval(timer)
    timer = setInterval(function () {
        iSpeed = (iTarget - obj.offsetTop) / 4;

        iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);

        if (obj.offsetTop == iTarget)
        { clearInterval(timer) }
        else { obj.style.top = obj.offsetTop + iSpeed + 'px' }
    }, 30)
}

function moveTarget() {
    if (oLoginBox.offsetWidth) {
        t = (document.documentElement.clientHeight - oLoginBoxHeight) / 2 + scrollTop;
        moveTop(oLoginBox, parseInt(t));
        oShade.style.height = scrollTop + document.documentElement.clientHeight + 'px';
    }
}

window.onscroll = window.onresize = function () {
    scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    moveTarget();
}

oClose.onclick = function () {
    oLoginBox.style.display = oShade.style.display = 'none'
}


var isLogin = false;

//判断是否登录状态
var bbsIsLogin = function () {
    
}
moveTarget();
setInterval(function () {
    if (oLoginBox.style.display == 'none') {
        //bbsIsLogin();
        moveTarget();
    }
}, 2000);
